import React, { useState, useEffect, useCallback } from "react";
import { wxLogin } from "@/services/login";

export default function useUser() {
  const [user, setUser] = useState({}); //微信用户信息

  const login = useCallback(
    (params, success) => {
      console.log("params", params);
      wxLogin(params)
        .then((res) => {
          if (res) {
            const userInfo = res.person || {};
            setUser(userInfo);
            console.log(res, "-----登录成功-------ss");
            success(userInfo);
          }
        })
        .catch((e) => {
          console.log(e, "error");
        });
    },
    [setUser]
  );

  return {
    user,
    setUser,
    login,
  };
}
